home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6039 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  992 b 

  1. Path: news.isys.net!usenet
  2. From: Henrik.Stellmann@Hamburg.NetSurf.DE (Henrik)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: How to the size of a file in C ?
  5. Date: Sun, 11 Feb 1996 20:19:37 +0100
  6. Organization: iSYS Informationssystem Hamburg
  7. Message-ID: <4flcj7$66h@trance.isys.net>
  8. References: <4ffeqa$pjh@brtph500.bnr.ca>
  9. NNTP-Posting-Host: dip101-1.hamburg.netsurf.de
  10. X-Newsreader: Forte Free Agent v0.38
  11.  
  12. Gilbert Banks <gilbertb@bnr.ca> wrote:
  13.  
  14. >How do I get the size of a file in C UNIX-based?  I tried sizeof <file>, but 
  15.  
  16. try this:
  17.  
  18. long FileSize (const char * FileName)
  19. {
  20. lont Fsize;
  21.  
  22.     FILE * File = fopen(FileName)
  23.     if (File)
  24.     {
  25.         Fsize= fseek (File,  0, *** ); 
  26.         fclose (File);
  27.         return FSize;
  28.     }
  29.     else
  30.     {
  31.          return -1;
  32.     }
  33.  
  34. }
  35.  
  36.  
  37. ***     Sorry, I don't remember the name of the constant to make fseek
  38.  
  39.     jump relative to the fileend. Please look in your C - reference for
  40.     fseek.
  41.  
  42. It's not the fastet way, and sure not sooo elegant. But it works.
  43. Maybe others have better ideas.
  44.  
  45.  
  46. Henrik :-)
  47.  
  48.  
  49.  
  50.